From 5d4fe5eddd2cedfb1b8e51a95948c9e06cab9f54 Mon Sep 17 00:00:00 2001 From: robertl Date: Mon, 12 Apr 2010 02:53:03 +0000 Subject: [PATCH] Improved error logging on upgrade failure. --- gui/babeldata.h | 14 ++++++++++++- gui/mainwindow.cpp | 16 +++++++------- gui/upgrade.cpp | 52 +++++++++++++++++++++++++++++++++------------- gui/upgrade.h | 12 ++++------- 4 files changed, 62 insertions(+), 32 deletions(-) diff --git a/gui/babeldata.h b/gui/babeldata.h index 2bf8c6eb8..c0b44cec1 100644 --- a/gui/babeldata.h +++ b/gui/babeldata.h @@ -1,5 +1,5 @@ // -*- C++ -*- -// $Id: babeldata.h,v 1.6 2010/04/11 18:11:46 robertl Exp $ +// $Id: babeldata.h,v 1.7 2010/04/12 02:53:04 robertl Exp $ //------------------------------------------------------------------------ // // Copyright (C) 2009 S. Khai Mong . @@ -57,6 +57,10 @@ public: upgradeCheckMethod(0), upgradeCheckTime(QDateTime(QDate(2001, 1, 1), QTime(0, 0))), installationUuid(QUuid::createUuid().toString()), + upgradeCallbacks(0), + upgradeDeclines(0), + upgradeErrors(0), + upgradeOffers(0), startupVersionCheck(true), reportStatistics(true), allowBetaUpgrades(false) @@ -102,6 +106,10 @@ public: sg.addVarSetting(new IntSetting("app.upgradeCheckMethod", upgradeCheckMethod)); sg.addVarSetting(new DateTimeSetting("app.upgradeCheckTime", upgradeCheckTime)); sg.addVarSetting(new StringSetting("app.installationUuid", installationUuid)); + sg.addVarSetting(new IntSetting("app.upgradeCallbacks", upgradeCallbacks)); + sg.addVarSetting(new IntSetting("app.upgradeDeclines", upgradeDeclines)); + sg.addVarSetting(new IntSetting("app.upgradeErrors", upgradeErrors)); + sg.addVarSetting(new IntSetting("app.upgradeOffers", upgradeOffers)); // Global preferences. sg.addVarSetting(new BoolSetting("app.startupVersionCheck", startupVersionCheck)); @@ -143,6 +151,10 @@ public: int upgradeCheckMethod; QDateTime upgradeCheckTime; QString installationUuid; + int upgradeCallbacks; + int upgradeDeclines; + int upgradeErrors; + int upgradeOffers; // Global preferences. bool startupVersionCheck; diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index b86782d1b..c525f350f 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -1,5 +1,5 @@ // -*- C++ -*- -// $Id: mainwindow.cpp,v 1.19 2010/04/11 22:38:06 robertl Exp $ +// $Id: mainwindow.cpp,v 1.20 2010/04/12 02:53:03 robertl Exp $ //------------------------------------------------------------------------ // // Copyright (C) 2009 S. Khai Mong . @@ -190,11 +190,10 @@ MainWindow::MainWindow(QWidget* parent): QMainWindow(parent) //--- Restore from registry restoreSettings(); - upgrade = new UpgradeCheck(parent, formatList); + upgrade = new UpgradeCheck(parent, formatList, bd); if (bd.startupVersionCheck) { - upgrade->checkForUpgrade(babelVersion, bd.upgradeCheckMethod, - bd.upgradeCheckTime, bd.installationUuid, - bd.reportStatistics, allowBetaUpgrades()); + upgrade->checkForUpgrade(babelVersion, bd.upgradeCheckTime, + allowBetaUpgrades()); } } @@ -1022,10 +1021,9 @@ void MainWindow::aboutActionX() //------------------------------------------------------------------------ void MainWindow::upgradeCheckActionX() { - upgrade->checkForUpgrade(babelVersion, bd.upgradeCheckMethod, - QDateTime(QDate(2000, 1, 1), QTime(0, 0)), - bd.installationUuid, - bd.reportStatistics, allowBetaUpgrades()); + upgrade->checkForUpgrade(babelVersion, + QDateTime(QDate(2000, 1, 1), QTime(0, 0)), + allowBetaUpgrades()); } //------------------------------------------------------------------------ diff --git a/gui/upgrade.cpp b/gui/upgrade.cpp index ca339aac9..415fd7bcd 100644 --- a/gui/upgrade.cpp +++ b/gui/upgrade.cpp @@ -1,5 +1,5 @@ // -*- C++ -*- -// $Id: upgrade.cpp,v 1.24 2010/04/11 18:11:47 robertl Exp $ +// $Id: upgrade.cpp,v 1.25 2010/04/12 02:53:04 robertl Exp $ /* Copyright (C) 2009, 2010 Robert Lipe, robertlipe@gpsbabel.org @@ -20,8 +20,9 @@ */ -#include "upgrade.h" +#include "babeldata.h" #include "format.h" +#include "upgrade.h" #include "../config.h" #include "../gbversion.h" @@ -44,9 +45,13 @@ static const bool testing = true; static const bool testing = false; #endif -UpgradeCheck::UpgradeCheck(QWidget *parent, QList &formatList) : +UpgradeCheck::UpgradeCheck(QWidget *parent, QList &formatList, + BabelData& bd) : QObject(parent), - http(0), formatList_(formatList), updateStatus_(updateUnknown) + http(0), + formatList_(formatList), + updateStatus_(updateUnknown), + bd_(bd) { } @@ -113,16 +118,13 @@ QString UpgradeCheck::getOsVersion() } -UpgradeCheck::updateStatus UpgradeCheck::checkForUpgrade(const QString ¤tVersionIn, - int checkMethod, +UpgradeCheck::updateStatus UpgradeCheck::checkForUpgrade( + const QString ¤tVersionIn, const QDateTime &lastCheckTime, - const QString &installationUuid, - bool reportStatistics, bool allowBeta) { currentVersion = currentVersionIn; currentVersion.remove("GPSBabel Version "); - upgradeCheckMethod = checkMethod; QDateTime soonestCheckTime = lastCheckTime.addDays(1); if (!testing && QDateTime::currentDateTime() < soonestCheckTime) { @@ -147,7 +149,7 @@ UpgradeCheck::updateStatus UpgradeCheck::checkForUpgrade(const QString ¤tV QString args = "current_version=" + currentVersion; args += "¤t_gui_version=" VERSION; - args += "&installation=" + installationUuid; + args += "&installation=" + bd_.installationUuid; args += "&os=" + getOsName(); #if HAVE_UNAME struct utsname utsname; @@ -160,6 +162,10 @@ UpgradeCheck::updateStatus UpgradeCheck::checkForUpgrade(const QString ¤tV args += QString("&beta_ok=%1").arg(allowBeta); args += "&lang=" + QLocale::languageToString(locale.language()); args += "&last_checkin=" + lastCheckTime.toString(Qt::ISODate); + args += QString("&ugcb=%1").arg(bd_.upgradeCallbacks); + args += QString("&ugdec=%1").arg(bd_.upgradeDeclines); + args += QString("&ugoff=%1").arg(bd_.upgradeOffers); + args += QString("&ugerr=%1").arg(bd_.upgradeErrors); int j = 0; @@ -172,7 +178,7 @@ UpgradeCheck::updateStatus UpgradeCheck::checkForUpgrade(const QString ¤tV if (wc) args += QString("&uc%1=wr/%2/%3").arg(j++).arg(formatName).arg(wc); } - if (j && reportStatistics) + if (j && bd_.reportStatistics) args += QString("&uc=%1").arg(j); if (false && testing) @@ -206,17 +212,33 @@ void UpgradeCheck::readResponseHeader(const QHttpResponseHeader &responseHeader) void UpgradeCheck::httpRequestFinished(int requestId, bool error) { - if (http == 0 || error) + bd_.upgradeCallbacks++; + + if (http == 0 || error) { + bd_.upgradeErrors++; return; + } - if (requestId != httpRequestId) + // This is not an error state; it's just the internal state of Qt's network + // stack flailing around. + if (requestId != httpRequestId) { return; + } QString oresponse(http->readAll()); QDomDocument document; - if (!document.setContent(oresponse)) + int line = -1; + QString error_text; + // This shouldn't ever be seen by a user. + if (!document.setContent(oresponse, &error_text, &line)) { + QMessageBox::critical(0, tr("Error"), + tr("Invalid return data at line %1: %2.") + .arg(line) + .arg( error_text)); + bd_.upgradeErrors++; return; + } QString response; QString upgradeText; @@ -248,6 +270,7 @@ void UpgradeCheck::httpRequestFinished(int requestId, bool error) upgradeText = upgrade.firstChildElement("overview").text(); // String compare, not a numeric one. Server will return "best first". if((updateVersion > currentVersion) && updateCandidate) { + bd_.upgradeOffers++; updateStatus_ = updateNeeded; response = tr("A new version of GPSBabel is available.
" "Your version is %1
" @@ -274,6 +297,7 @@ void UpgradeCheck::httpRequestFinished(int requestId, bool error) // downloadUrl.addQueryItem("os", getOsName()); QDesktopServices::openUrl(downloadUrl); default: ; + bd_.upgradeDeclines++; } } diff --git a/gui/upgrade.h b/gui/upgrade.h index 880380b3f..a782a8451 100644 --- a/gui/upgrade.h +++ b/gui/upgrade.h @@ -19,6 +19,7 @@ */ +#include "babeldata.h" #include "format.h" #include #include @@ -30,8 +31,7 @@ class QHttpResponseHeader; class UpgradeCheck : public QObject { Q_OBJECT public: - //UpgradeCheck(QWidget *parent = 0); - UpgradeCheck(QWidget *parent, QList &formatList); + UpgradeCheck(QWidget *parent, QList &formatList, BabelData& bd); ~UpgradeCheck(); typedef enum { @@ -39,14 +39,9 @@ public: updateCurrent, updateNeeded, } updateStatus; - UpgradeCheck::updateStatus checkForUpgrade(const QString &babelVersion, - int upgradeCheckMethod, const QDateTime &lastCheckTime, - const QString &installationUuid, - bool reportStatistics, - bool allowBeta - ); + bool allowBeta); QDateTime getUpgradeWarningTime() { return upgradeWarningTime; } @@ -70,6 +65,7 @@ protected: QString getOsVersion(void); QList &formatList_; updateStatus updateStatus_; + BabelData& bd_; private slots: void httpRequestFinished(int requestId, bool error); -- 2.30.2